#include "ABCamera.h"

ABCamera::ABCamera()
: m_eyePos(0.0f, 0.0f, 0.0f)
, m_isActive(false)
, m_yawPitchRoll(0.0f, 0.0f, 0.0f)
, m_pAttached(NULL)
, m_pTracked(NULL)
{
	//Create a new frustum for the camera
	m_pFrustum = new Frustum();
}

ABCamera::~ABCamera()
{
	if(m_pFrustum)
	{
		delete m_pFrustum;
		m_pFrustum = NULL;
	}
}
void ABCamera::UpdateFrustum(D3DXMATRIX& m)
{
	//Give the 6 frustum planes
	D3DXPLANE front(m._13, m._23, m._33, m._43); 
	D3DXPLANE back(m._14 - m._13, m._24 - m._23, m._34 - m._33, m._44 - m._43);
	D3DXPLANE left(m._14 + m._11, m._24 + m._21, m._34 + m._31, m._44 + m._41);
	D3DXPLANE right(m._14 - m._11, m._24 - m._21, m._34 - m._31, m._44 - m._41);
	D3DXPLANE bottom(m._14 + m._12, m._24 + m._22, m._34 + m._32, m._44 + m._42);
	D3DXPLANE top(m._14 - m._12, m._24 - m._22, m._34 - m._32, m._44 - m._42);

	//Update the frustum with the 6 planes
	m_pFrustum->Setup(left, right, top, bottom, front, back);
}
void ABCamera::Attach(const GameObject& a_gameObject)
{
	m_pAttached = &a_gameObject;
}

void ABCamera::Track(const GameObject& a_gameObject)
{
	m_pTracked = &a_gameObject;
}
